﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Collections;

public class ResponseGroup : IEnumerable<KeyValuePair<ResponseType, int>> {
  private int m_Total;
  private SortedDictionary<ResponseType, int> m_Values = new SortedDictionary<ResponseType, int>();

  public int Total {
    get { return m_Total; }
  }

  public void Add(ResponseType responseType) {
    int value = 0;
    m_Values.TryGetValue(responseType, out value);
    value++;
    m_Total++;
    m_Values[responseType] = value;
  }

  public int this[ResponseType key] {
    get { return m_Values[key]; }
  }

  public bool HasResponse(ResponseType response) {
    return m_Values.ContainsKey(response);
  }

  #region IEnumerable<KeyValuePair<ResponseType,int>> Members

  public IEnumerator<KeyValuePair<ResponseType, int>> GetEnumerator() {
    return m_Values.GetEnumerator();
  }

  #endregion

  #region IEnumerable Members

  IEnumerator IEnumerable.GetEnumerator() {
    return ((IEnumerable)m_Values).GetEnumerator();
  }

  #endregion

  public int GetPercentValue(ResponseType responseType) {
    return (int)((m_Values[responseType] * 100) / m_Total);
  }
}
